#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

class Graph {
	int size;
	bool** graph;

	void init()
	{
		graph = new bool*[size];
		cout << isConnected(graph, 5) << endl;
		for (int i = 0; i < size; i++) {
			graph[i] = new bool[size];
		}
		// Initialize all to false
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				if (i == j) graph[i][j] = false;
				else {
					graph[i][j] = graph[j][i] = true;
						//(prob() < 0.21);
				}
			}
		}

	}

public:
	Graph(int size)
	{
		this->size = size;
		init();
	}

	bool isConnected(bool** graph, int size)
	{
		int oldSize = 0;
		int cSize = 0;
		bool* close = new bool[size];
		bool* open = new bool[size];
		for (int i = 0; i < size; i++) {
			open[i] = close[i] = false;
		}
		open[0] = 0;
		while (cSize < size) {
			for (int i = 0; i < size; i++) {
				oldSize = cSize;
				if (open[i] && (close[i] == false)) {
					close[i] = true;
					cSize++;
				}
				for (int j = 0; j < size; j++) {
					open[j] = open[j] || graph[i][j];
				}
			}
			if (cSize == size) return true;
			if (oldSize == cSize) return false;
		}
	}

	void print()
	{
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				cout << graph[i][j] << " ";
			}
			cout << endl;
		}
	}
	
};

int main(void)
{
	int n = 5;
	Graph graph(n);

	//cout << isConnected(graph, n) << endl;
	
	return 0;
}
